<?php
//var_dump($_POST);

$accout = $_POST['accout'];
if (!preg_match("/0?(13|14|15|17|18|19)[0-9]{9}/",$accout)){
    echo "手机格式错误";
    die();
}
$password = $_POST['password'];

if (strlen($password) < 6){
    echo "密码格式错误";
    die();
}

$users = array("user"=>$accout,"pass"=>$password);
$data = file_get_contents("users.json");
$json = $data == ''? array():json_decode($data,true);

foreach ($json as $user){
    if ($accout == $user['user']){
        echo "用户已存在";
        die();
    }
}
array_push($json,$users);

//$jsonstr = fopen("users.json","a+");
//fwrite($jsonstr,"");
//fwrite($jsonstr,json_encode($json));
//fclose("users.json");
file_put_contents("users.json","");
$esc = file_put_contents("users.json",json_encode($json));
if ($esc){
    echo "注册成功";
}else{
    echo "注册失败";
}